package com.carmanage.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.carmanage.dao.ILineDao;
import com.carmanage.domain.Line;

@Controller
public class LineController {

	@Resource
	private ILineDao lineDao;
	
	public void setILineDao(ILineDao lineDao){
		this.lineDao = lineDao;
	}
	
	public ILineDao getILineDao(){
		return lineDao;
	}
	
	@RequestMapping(value="/saveRoute")
	public void saveRoute(Line line,HttpServletResponse response){
		lineDao.saveLine(line);
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.println("success");
			
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.flush();
			out.close();
		}
	}
	
	@RequestMapping(value="/getAllRoute")
	public @ResponseBody List<Line> getAllRoute(){
		List<Line> lines = lineDao.getAllLine();
		return lines;
	}
}
